﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace websitev2.Controllers
{
    public class ArticlesController : Controller
    {
        //
        // GET: /Articles/

        public Models.StartStopEntities db = new Models.StartStopEntities(); 

        public ActionResult Index()
        {
            

            return View();
        }


        public ActionResult News(string ID)
        {
            if (ID == null)
            {
                // return to recent articles list
                return RedirectToAction("index", "articles");
            }

            Int64 ContentID = 0;
            try
            {
                ContentID = Int64.Parse(ID);
            }
            catch { }

            var news = db.SiteContents.FirstOrDefault(a => a.ContentID == ContentID);
            if (news == null)
            {
                news = db.SiteContents.FirstOrDefault(a => a.ContentLocator == ID); 
            }
         
            // Lets drop a null thing in here. 
            if (news == null)
            {
                return RedirectToAction("index", "articles");
            }

            #region SEO

            ViewBag.Title = news.Title + " | Startstop.me, all your stats in one place";
            #endregion 

            #region Additional articles links on the right
            var morearticles = (from content in db.SiteContents
                             where content.ContentTag=="home" 
                                orderby content.CreatedOn descending
                            select content).Take(10)
                         ;

            ViewBag.MoreArticles = morearticles;


            #endregion 

            return View(news); 
        }

      
    }
}
